using System.Threading;
using System;
using Microsoft.SPOT;
using System.Net;
using System.Text;
using System.Net.Sockets;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Hardware;
using DeviceSolutions.SPOT.Hardware;
namespace HouseControl
{
    class Alarm
    {

        

        public static void start_alarm_thread()
        {
            double temperature;  //variable that will store heat values
           

            while (true)
            {

                  temperature=Heat_Control.temperature.ReadTemperature(); //read the temperature
                  
                   // we turn off or or on the Alarm in function of the different cases
                  if ((Program.min_temp_set == true) && (Program.max_temp_set == true))
                  {
                      
                      if ((Program.min_temp <= temperature ) && (temperature <= Program.max_temp))
                      {
                          // Alarm is off
                          Program.alarm_min_reached = false; //this is set to true then the Tahoe can send the status of the alarm to the Android App
                           Program.alarm_max_reached = false; //this is set to true then the Tahoe can send the status of the alarm to the Android App


                      }

                      else 
                      {
                          //turn on  Alarm

                          Program.alarm.SetAlarm_SPI(); //trigger on the alarm

                          if (temperature <= Program.min_temp) Program.alarm_min_reached = true; //set to true then the Tahoe can send the status of the alarm to the Android App
                          else if (temperature >= Program.max_temp)Program.alarm_max_reached = true; //this is set to true then the Tahoe can send the status of the alarm to the Android App

                          //we reset them to false
                          Program.min_temp_set = false;
                          Program.max_temp_set = false;
                      }
                      
                  }
                //we give some ressources to the system...
                  
                Thread.Sleep(10000);
            }
        }
    }
}
